package cpa.prowon.gui;

import java.util.Collection;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import pho.prowon.category.IndexCategory;

/**
 * The categorization tree content provider provides the information for the
 * picture categorization viewer on the left side of the window. It's used
 * to view pictures in categorized way
 * @author Chris
 */
public class CategorizationTreeContentProvider implements ITreeContentProvider {

	/**
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object)
	 */
	public Object[] getChildren(Object element) {
		
		// Get the categories of the index category, if none are available, return an empty list
		Collection cl = ((IndexCategory) element).getCategories();
		if (cl.isEmpty() == false)
		{
			return cl.toArray();
		}
		return new Object[0];
	}

	/**
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object)
	 */
	public Object getParent(Object element) {
		
		// Return the parent of the index category
		return ((IndexCategory) element).getParent();
		
	}

	/**
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object)
	 */
	public boolean hasChildren(Object element) {
		
		// Return whether the index category has sub categories or not
		return ((IndexCategory) element).hasCategories();
		
	}

	/**
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
	 */
	public Object[] getElements(Object element) {
		
		// Return the children of the index category
		return getChildren(element);
		
	}

	/**
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
	 */
	public void dispose() {
	}

	/**
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
	 */
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
	}

}
